home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / haeberli / abekas / scread.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  2KB  |  106 lines

  1.  
  2. /* scread.c         1991 Abekas Video Systems  - Simon Carter */
  3. /*                                                          */
  4. /* This program reads one field at a time from an A60 on    */
  5. /* the SCSI port.  The syncs and line numbers included in   */
  6. /* the SCSI transfer must be stripped separately.  Degoop   */
  7. /* may be used for this function.                           */
  8. /*                                                          */
  9. /*           cc -g scread.c -lds -o scread                      */
  10.  
  11. #include <fcntl.h>
  12. #include <stdio.h>
  13. #include <sys/types.h>
  14.  
  15. # include <dslib.h>
  16.  
  17. #ifdef LINES_525
  18. #define FIELDLEN 0x5D000
  19. #define TMO 400
  20. #else
  21. #define FIELDLEN 0x6E000
  22. #define TMO 800
  23. #endif
  24. #define BLOCKSIZE 512
  25.  
  26.  
  27. /*
  28. extern int dsreqflags;
  29. */
  30. extern int dsdebug;
  31.  
  32. int dsblksize;
  33.  
  34. myreadextended28(dsp, data, datalen, lba, vu)
  35. struct dsreq *dsp;
  36. caddr_t data;
  37. long datalen, lba;
  38. char vu;
  39. {
  40. fillg1cmd(dsp, CMDBUF(dsp), G1_READ, 0, B4(lba), 0, B2(datalen), B1(vu<<6));
  41. filldsreq(dsp, data, datalen*dsblksize, DSRQ_READ /* |DSRQ_CTRL2 */ );
  42. dsp->ds_time = TMO;   /* often takes a while */
  43. return(doscsireq(getfd(dsp), dsp));
  44. }
  45.  
  46.  
  47. main(argc, argv)
  48. int argc;
  49. char *argv[];
  50. {
  51. char *devpath = "/dev/scsi/sc0d5l0";       /* name of device to open */
  52. FILE *myfile;
  53. int i, chunk, fieldnum, block, res;
  54. struct dsreq *dsp;
  55. char field[FIELDLEN], *ptr;
  56.  
  57. if(argc != 3)
  58.     {
  59.     printf("Usage scread <field> file\n");
  60.     exit();
  61.     }
  62.  
  63. fieldnum = atoi(argv[1]);
  64. if(!(myfile = fopen(argv[2], "w")))
  65.     {
  66.     printf("Unable to open file %s\n", argv[2]);
  67.     exit();
  68.     }
  69.  
  70.  
  71. dsreqflags = DSRQ_SENSE | DSRQ_DISC;
  72. dsdebug = 0;
  73. dsblksize = BLOCKSIZE;
  74.  
  75. if ((dsp = dsopen(devpath,O_RDONLY)) == NULL)
  76.     {
  77.     printf("unable to open device\n");
  78.     exit();
  79.     }
  80.  
  81. /* clear check cond.    */
  82. if (testunitready00(dsp) != 0)
  83.     {
  84.     printf("device not ready\n");
  85.     exit();
  86.     }
  87.  
  88.  
  89. block = fieldnum * (FIELDLEN/BLOCKSIZE);
  90. chunk = (FIELDLEN/BLOCKSIZE)/8;
  91. ptr = field;
  92. for(i=0;i<8;i++,ptr+=(chunk*BLOCKSIZE),block+=chunk)
  93.     if(res = myreadextended28(dsp, ptr, chunk, block, 0)) break;
  94.  
  95. if(res)
  96.     {
  97.     printf("error from scread %d\n", i);
  98.     if (testunitready00(dsp) != 0)
  99.     printf("device not ready\n");
  100.     exit();
  101.     }
  102.  
  103. fwrite(field, 1, FIELDLEN, myfile);
  104. }
  105.  
  106.